﻿@model Telerik.Web.Mvc.GridModel<MeasureDimensionModel>
@using Telerik.Web.Mvc.UI;
@using System.Linq;
@{
    //page title
    ViewBag.Title = @T("Admin.Configuration.Measures.Dimensions").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-content.png")" alt="" />
        @T("Admin.Configuration.Measures.Dimensions")
    </div>
</div>
<table class="adminContent">
    <tr>
        <td>
            <b>@T("Admin.Configuration.Measures.Dimensions.Description")</b>
        </td>
    </tr>
    <tr>
        <td>
            @(Html.Telerik().Grid(Model.Data)
                    .Name("measuredimension-grid")
                    .DataKeys(x =>
                    {
                        x.Add(y => y.Id).RouteKey("Id");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Name).Width(200);
                        columns.Bound(x => x.SystemKeyword).Width(150);
                        columns.Bound(x => x.Ratio).Width(100);
                        columns.Bound(x => x.DisplayOrder).Width(100);
                        columns.Bound(x => x.IsPrimaryDimension).Width(100)
                            .Template(x => x.IsPrimaryDimension.ToString().ToLower()).ReadOnly();
                        columns.Command(commands => commands.Select())
                            .Title(T("Admin.Configuration.Measures.Dimensions.Fields.MarkAsPrimaryDimension").Text).Width(100);
                        columns.Command(commands =>
                        {
                            commands.Edit();
                            commands.Delete();
                        }).Width(180);

                    })
                    .ToolBar(x => x.Insert())
                    .Editable(x =>
                    {
                        x.Mode(GridEditMode.InLine);
                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax().Select("Dimensions", "Measure")
                            .Update("DimensionUpdate", "Measure")
                            .Delete("DimensionDelete", "Measure")
                            .Insert("DimensionAdd", "Measure");
                    })
                    .ClientEvents(x => x.OnError("grid_onError"))
                    .EnableCustomBinding(true))
            <script type="text/javascript">
                function grid_onError(e) {
                    alert(e.XMLHttpRequest.responseText);
                    e.preventDefault();
                }
            </script>
        </td>
    </tr>
</table>
